package com.woniuxy.purchasemanager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.commons.entity.purchaseManager.DemandGoodsEntity;
import com.woniuxy.commons.entity.purchaseManager.NeedAllocationEntity;
import com.woniuxy.commons.entity.purchaseManager.NeedAndGoodsEntity;
import com.woniuxy.purchasemanager.dao.DemandGoodsDao;
import com.woniuxy.purchasemanager.dao.NeedAllocationDao;
import com.woniuxy.purchasemanager.dao.NeedAndGoods;
import com.woniuxy.purchasemanager.service.DemandGoods;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:黄志超
 * @Todo:TODO
 * @DateTime:2022/4/26 17:55
 * @Component:蜗牛
 **/
@Service
public class DemandGoodsImpl extends ServiceImpl<DemandGoodsDao , DemandGoodsEntity> implements DemandGoods {
    @Resource
    private NeedAllocationDao allocationDao;

    @Resource
    private NeedAndGoods needAndGoods;

    @Resource
    private DemandGoodsDao demandGoodsDao;
    @Override
    public Map<String, Object> getList(String oddNumber, Integer currentPage, Integer pageSize) {
       Map<String, Object> map = new HashMap<String, Object>();
       QueryWrapper queryWrapper =  new QueryWrapper<>();
       queryWrapper.eq("odd_number",oddNumber);
        NeedAllocationEntity needAllocationEntity = allocationDao.selectOne(queryWrapper);
        Integer needId = needAllocationEntity.getNeedId();
        QueryWrapper<NeedAndGoodsEntity> queryWrapper1 =  new QueryWrapper<>();
        queryWrapper1.eq("need_id",needId);
        List<NeedAndGoodsEntity> needAndGoodsEntities = needAndGoods.selectList(queryWrapper1);
        System.out.println(needAndGoodsEntities.toString());
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < needAndGoodsEntities.size();i++){
            QueryWrapper<DemandGoodsEntity> queryWrapper2 =  new QueryWrapper<>();
            queryWrapper2.eq("goods_id",needAndGoodsEntities.get(i).getGoodsId());
            DemandGoodsEntity demandGoodsEntity = demandGoodsDao.selectOne(queryWrapper2);
            arrayList.add(demandGoodsEntity);
        }
        map.put("needAllocationEntity",needAllocationEntity);
        map.put("demandGoodsEntity",arrayList);
        return map;
    }
}
